import QMFetch from "qm-ux/lib/QMFetch";
import QMConst from "qm-ux/lib/QMConst";
import { getSystemCode } from "../../apps/x-site/common/const-value";
//import fetch from 'isomorphic-fetch'
const ajax = (param = {}) => {
  return QMFetch(param)
    .then(response => {
      if (response.err) {
        return Promise.reject(response.err);
      }
      return response.data;
    })
    .catch(err => {
      //未发出请求
      return Promise.reject(err);
    });
};

export const domainList = () => {
  const Type = {
    d2c: ["c", "w"],
    d2p: ["b", "x", "a"]
  };
  const systemCode = getSystemCode();
  let apiKey = "v_d2c_api";
  if (systemCode === "d2p") {
    apiKey = "v_d2p_api";
  }
  let apiHost = QMConst.get("host." + apiKey);
  return ajax({
    host: apiHost,
    url: `domain/list`,
    method: "POST",
    body: Type[systemCode]
  });
};
